// pages/seal/sealadmin.js
Page({
  mixins: [require('../mixin/themeChanged')],

  /**
   * 页面的初始数据
   */
  data: {
    content:[],
    token:"",
    currentopenid:"",
    currentindex:"",
    currentid:"",

  },


 
  pushmessage:function(e){
    var that =this
    var url = wx.getStorageSync("config") 
   
    this.setData({
      currentopenid: e.currentTarget.dataset.openid,
      currentindex:e.currentTarget.dataset.index,
      currentid:e.currentTarget.dataset.id
 
    })
    console.log(that.data.currentopenid)
    wx.showModal({
      title: '通知确认',
      content: '是否确认通知前来',
      success: function (res) {
        if (res.confirm) {


          //请求体
          wx.request({
            url: url.service.homeUrl + '/card/pushmessage',
            data: {
              openid: that.data.currentopenid,
              id:that.data.currentid
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,         
              });

              var newcontent =[]
              newcontent=that.data.content
              newcontent.splice(that.data.currentindex,1)
              that.setData({
                content: newcontent,
              })
              


            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })
        }
      }
    })

  },


  pushdeny:function(e){
    var that =this
    var url = wx.getStorageSync("config") 
   
    this.setData({
      currentopenid: e.currentTarget.dataset.openid,
      currentindex:e.currentTarget.dataset.index,
      currentid:e.currentTarget.dataset.id
 
    })
    console.log(that.data.currentopenid)
    wx.showModal({
      title: '通知确认',
      content: '是否确认通知前来',
      success: function (res) {
        if (res.confirm) {


          //请求体
          wx.request({
            url: url.service.homeUrl + '/card/pushdeny',
            data: {
              openid: that.data.currentopenid,
              id:that.data.currentid
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,         
              });

              var newcontent =[]
              newcontent=that.data.content
              newcontent.splice(that.data.currentindex,1)
              that.setData({
                content: newcontent,
              })
              


            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })
        }
      }
    })

  },


  changeTheme: function () {
    console.log(this.data);
    getApp().themeChanged(this.data.theme === 'light' ? 'dark' : 'light');
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var url = wx.getStorageSync("config")
    var city = wx.getStorageSync("city")


    wx.request({
      url: url.service.homeUrl + '/card/showcardorder',
      data: {
        city:city

      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {

        that.setData({
          content: res.data,
        })


      },
      fail: function (res) {},
      complete: function (res) {},
    })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})